package provenance_temp;
import java.io.File;
import uk.ac.kcl.inf.provoking.builder.ProvBuilder;
import uk.ac.kcl.inf.provoking.model.Document;
import uk.ac.kcl.inf.provoking.serialise.rdf.turtle.TurtlePrinter;

class BuilderExample {

  public static void main (String[] arguments) throws Exception {
   // Set up the builder with the vocabularies we will use

   ProvBuilder b = new ProvBuilder ("ex:", 
       "http://www.inf.kcl.ac.uk/staff/simonm/provoking#");
   b.setPrefix ("dcterms:", "http://purl.org/dc/terms/");
   b.setPrefix ("foaf:", "http://xmlns.com/foaf/0.1/");

   // Primer example: entities, activities, generation and usage

   b.entity ("article", "dcterms:title=Crime rises in cities");
   b.entity ("composition").wasGeneratedBy ("*1").activity ("compose");
   b.activity ("compose").used ("*2").entity ("dataSet1");
   b.activity ("compose").used ("*3").entity ("regionList");
   b.entity ("chart1").wasGeneratedBy ().activity ("illustrate").
       used ().entity ("composition");

   // Primer example: agents and responsibility

   b.activity ("compose").wasAssociatedWith ("*4").
       person ("derek", "foaf:givenName=Derek", "foaf:mbox=mailto:derek@example.org");
   b.activity ("illustrate").wasAssociatedWith ().person ("derek");
   b.person ("derek").actedOnBehalfOf ().
       organization ("chartgen", "foaf:name=Chart Generators Inc");
   b.entity ("chart1").wasAttributedTo ().person ("derek");

   // Primer example: roles

   b.where ("*1").role ("ex:composedData");
   b.where ("*2").role ("ex:dataToCompose");
   b.where ("*3").role ("ex:regionsToAggregateBy");
   b.where ("*4").role ("ex:analyst");

   // Primer example: revision and derivation

   b.entity ("dataSet2").wasRevisionOf ().entity ("dataSet1");
   b.entity ("chart2").wasDerivedFrom ().entity ("dataSet2");
   b.entity ("chart2").wasRevisionOf ().entity ("chart1");

   // Primer example: plans

   b.activity (b.xsdDate ("2012-03-31T09:21:00"),
      b.xsdDate ("2012-04-01T15:21:00"), "correct");
   b.activity ("correct").wasAssociatedWith ("correcting").person ("edith").
      where ("correcting").plan ("instructions");
   b.entity ("dataSet2").wasGeneratedBy ().activity ("correct");

   // Primer example: time

   b.entity ("chart1").wasGeneratedBy (b.xsdDate ("2012-03-02T10:30:00")).
      activity ("compile1");
   b.entity ("chart2").wasGeneratedBy (b.xsdDate ("2012-04-01T15:21:00")).
      activity ("compile2");

   // Primer example: alternates and specialization

   b.entity ("blogEntry").wasQuotedFrom ().entity ("article");
   b.entity ("articleV1").specializationOf ().entity ("article");
   b.entity ("articleV2").specializationOf ().entity ("article");
   b.entity ("articleV2").alternateOf ().entity ("articleV1");

   // Finished building the document

   Document document = b.build ();

   // Write the document to a Turtle RDF file

   TurtlePrinter out = new TurtlePrinter (new File ("primer.ttl"));
   out.serialise (document);
   out.close ();
  }
}